#dataset reduction function.
#source - input dataset
#factor - (0;1) scaling factor
#apriori - desired output a priori probabilites for classes 1-4
function M = reduceSet(source,factor,apriori=[0.25,0.25,0.25,0.25])
    M=[];
    total = size(source,1);
    for i=1:4
        temp=source(source(:,1)==i,:);
        temp=temp(randperm(size(temp,1)),:);
        temp(1:end>factor*apriori(1,i)*size(source,1),:)=[];
        M=[M;temp];
    end;
end;
